package com.longxi.tianjintianbao.ui.activity.assetscheck;

import android.content.SharedPreferences;
import android.widget.Button;
import android.widget.LinearLayout;

import com.longxi.tianjintianbao.AppConst;
import com.longxi.tianjintianbao.MyApplication;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.api.ApiRetrofit;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.presenter.assetscheck.AssetsWebServiceAtPresenter;
import com.longxi.tianjintianbao.ui.view.assetscheck.IAssetsWebServiceAtView;

import butterknife.BindView;

/**
 * Created by cxw on & 2018/12/13
 */
public class AssetsWebServiceActivity extends BaseActivity<IAssetsWebServiceAtView, AssetsWebServiceAtPresenter> implements IAssetsWebServiceAtView {


    @BindView(R.id.llLogin)
    LinearLayout llLogin;
    @BindView(R.id.btnLogin)
    Button btnLogin;

    @BindView(R.id.llZCPD)
    LinearLayout llZCPD;
    @BindView(R.id.btnAssetInventory)
    Button btnAssetInventory;
    @BindView(R.id.btnAssetQuery)
    Button btnAssetQuery;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_assets_web_service;
    }

    @Override
    public void initView() {
        super.initView();
        mPresenter.setBar();
        mPresenter.isShowLoginBtn();
    }

    @Override
    public void initData() {
        super.initData();
        MyApplication.IP = "http://122.112.207.114:9126/tjtbzcApp/api/Interface/";
        MyApplication.IPID = "3";
        MyApplication.COMPANY = "天津天保";
        ApiRetrofit.clearInstance();//清除ApiRetrofit
    }

    @Override
    public void initListener() {
        super.initListener();
        btnLogin.setOnClickListener(v -> mPresenter.isShowLoginBtn());
        btnAssetInventory.setOnClickListener(v -> jumpToActivity(AssetsWebServiceInventoryActivity.class));
        btnAssetQuery.setOnClickListener(v -> jumpToActivity(TestActivity3.class));
    }

    @Override
    protected AssetsWebServiceAtPresenter createPresenter() {
        return new AssetsWebServiceAtPresenter(this);
    }

    @Override
    public LinearLayout getLlLogin() {
        return llLogin;
    }

    @Override
    public Button getBtnLogin() {
        return btnLogin;
    }

    @Override
    public LinearLayout getLlZCPD() {
        return llZCPD;
    }

    @Override
    public Button getBtnAssetInventory() {
        return btnAssetInventory;
    }

    @Override
    public Button getBtnAssetQuery() {
        return btnAssetQuery;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyApplication.IP = getSp("IP");
        MyApplication.IPID = getSp("IPID");
        MyApplication.COMPANY = getSp("COMPANY");
        ApiRetrofit.clearInstance();//清除ApiRetrofit
    }

    public String getSp(String key){
        SharedPreferences pf = MyApplication.getInstance().getSharedPreferences(AppConst.TAG, 0);
        return pf.getString(key, "");
    }
}
